package com.cctvcc.auth.controller;

import cn.cctvcc.core.domain.R;
import com.cctvcc.auth.domain.LoginBody;
import com.cctvcc.auth.domain.RegisterBody;
import com.cctvcc.auth.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 鉴权控制类
 * @author: Jiang
 * @create: 2021-09-23 14:38
 */
@RestController
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 登录
     */
    @PostMapping(value = "/login")
    public R<?> lgoin(@RequestBody LoginBody loginBody) throws Exception {
        return authService.login(loginBody);
    }

    /**
     * 登出
     */
    @PostMapping(value = "/logout")
    public R<?> logout() {
        return authService.logout();
    }

    /**
     * 获取公钥
     */
    @GetMapping(value = "/getPublicKey/{username}")
    public R<?> getPublicKey(@PathVariable("username") String username) throws Exception {
        return authService.getPublicKey(username);
    }

    /**
     * 注册
     */
    @PostMapping(value = "/register")
    public R<?> register(@RequestBody RegisterBody registerBody){
        return authService.register(registerBody);
    }

    /**
     * 忘记密码
     */
    @PostMapping(value = "/forget")
    public R<?> forget(@RequestParam("emailValue") String emailValue, @RequestParam("code") String code){

        return authService.forget(emailValue, code);
    }

    /**
     * 重置密码
     */
    @PutMapping(value = "/resetpass")
    public R<Integer> resetpass(@RequestParam("password") String password){

        return authService.resetpass(password);
    }

    /**
     * 发送邮箱验证码
     */
    @PostMapping(value = "/getEmailCode")
    public R<?> getEmailCode(@RequestParam("emailValue") String emailValue, @RequestParam("emailType") String eamilType){

        return authService.getEmailCode(emailValue, eamilType);
    }

    /**
     * 检查用户是否唯一
     */
    @GetMapping(value = "/checkUserNameUnique/{userName}")
    public R<String> checkUserNameUnique(@PathVariable("userName") String userName){
        return authService.checkUserNameUnique(userName);
    }


}
